<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调味品商店管理系统 - Enterprise Management System</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="app-wrapper">
        <!-- 顶部导航栏 -->
        <header class="app-header">
            <div class="header-content">
                <div class="logo-section">
                    <h1 class="logo">调味品商店管理系统</h1>
                    <span class="subtitle">Enterprise Management System</span>
                </div>
                <div class="header-actions">
                    <div class="current-time" id="currentTime"></div>
                </div>
            </div>
        </header>

        <!-- 统计面板 -->
        <section class="stats-section">
            <div class="stats-container">
                <div class="stat-card">
                    <div class="stat-icon employees-icon">👥</div>
                    <div class="stat-content">
                        <div class="stat-label">员工总数</div>
                        <div class="stat-value" id="totalEmployees">-</div>
                    </div>
                </div>
                <div class="stat-card">
                    <div class="stat-icon products-icon">📦</div>
                    <div class="stat-content">
                        <div class="stat-label">产品总数</div>
                        <div class="stat-value" id="totalProducts">-</div>
                    </div>
                </div>
                <div class="stat-card alert-card">
                    <div class="stat-icon warning-icon">⚠️</div>
                    <div class="stat-content">
                        <div class="stat-label">低库存预警</div>
                        <div class="stat-value" id="lowStockCount">-</div>
                    </div>
                </div>
                <div class="stat-card alert-card">
                    <div class="stat-icon expiry-icon">⏰</div>
                    <div class="stat-content">
                        <div class="stat-label">即将过期</div>
                        <div class="stat-value" id="expiringCount">-</div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 主内容区 -->
        <main class="main-content">
            <!-- 侧边导航 -->
            <aside class="sidebar">
                <nav class="nav-menu">
                    <button class="nav-item active" data-tab="dashboard">
                        <span class="nav-icon">📊</span>
                        <span class="nav-label">数据仪表盘</span>
                    </button>
                    <button class="nav-item" data-tab="employees">
                        <span class="nav-icon">👥</span>
                        <span class="nav-label">员工管理</span>
                    </button>
                    <button class="nav-item" data-tab="products">
                        <span class="nav-icon">📦</span>
                        <span class="nav-label">库存管理</span>
                    </button>
                    <button class="nav-item" data-tab="sales">
                        <span class="nav-icon">💰</span>
                        <span class="nav-label">销售记录</span>
                    </button>
                    <button class="nav-item" data-tab="alerts">
                        <span class="nav-icon">⚠️</span>
                        <span class="nav-label">预警中心</span>
                    </button>
                    <button class="nav-item" data-tab="analysis">
                        <span class="nav-icon">📈</span>
                        <span class="nav-label">数据分析</span>
                    </button>
                    <button class="nav-item" data-tab="history">
                        <span class="nav-icon">📋</span>
                        <span class="nav-label">销售历史</span>
                    </button>
                </nav>
            </aside>

            <!-- 内容区域 -->
            <div class="content-area">
                <!-- 仪表盘 -->
                <div class="tab-panel active" id="dashboard">
                    <div class="panel-header">
                        <h2>数据仪表盘</h2>
                        <div style="display: flex; gap: 12px;">
                            <button class="btn btn-secondary" onclick="exportPayroll()">导出薪资表</button>
                            <button class="btn-refresh" onclick="refreshCurrentTab()">刷新数据</button>
                        </div>
                    </div>
                    <div class="dashboard-grid">
                        <div class="panel-card">
                            <div class="card-header">
                                <h3>员工薪资报告</h3>
                            </div>
                            <div class="card-body">
                                <div class="table-container">
                                    <table class="data-table" id="payrollTable">
                                        <thead>
                                            <tr>
                                                <th>员工ID</th>
                                                <th>姓名</th>
                                                <th>职位</th>
                                                <th>绩效目标</th>
                                                <th>当前绩效</th>
                                                <th>实际薪资</th>
                                            </tr>
                                        </thead>
                                        <tbody id="payrollList">
                                            <tr><td colspan="6" class="loading">加载中...</td></tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="panel-card">
                            <div class="card-header">
                                <h3>库存概览</h3>
                            </div>
                            <div class="card-body">
                                <div class="table-container">
                                    <table class="data-table" id="inventoryTable">
                                        <thead>
                                            <tr>
                                                <th>SKU</th>
                                                <th>产品名称</th>
                                                <th>类别</th>
                                                <th>单价</th>
                                                <th>库存数量</th>
                                                <th>补货阈值</th>
                                                <th>过期日期</th>
                                            </tr>
                                        </thead>
                                        <tbody id="inventoryList">
                                            <tr><td colspan="7" class="loading">加载中...</td></tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 员工管理 -->
                <div class="tab-panel" id="employees">
                    <div class="panel-header">
                        <h2>员工管理</h2>
                    </div>
                    <div class="panel-grid">
                        <div class="panel-card">
                            <div class="card-header">
                                <h3>添加新员工</h3>
                            </div>
                            <div class="card-body">
                                <form id="addEmployeeForm" class="form-panel">
                                    <div class="form-group">
                                        <label for="empId">员工ID <span class="required">*</span></label>
                                        <input type="text" id="empId" required>
                                    </div>
                                    <div class="form-group">
                                        <label for="empName">姓名 <span class="required">*</span></label>
                                        <input type="text" id="empName" required>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group">
                                            <label for="empRole">职位 <span class="required">*</span></label>
                                            <input type="text" id="empRole" required>
                                        </div>
                                        <div class="form-group">
                                            <label for="empContact">联系方式 <span class="required">*</span></label>
                                            <input type="text" id="empContact" required>
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group">
                                            <label for="empSalary">基本工资 (¥) <span class="required">*</span></label>
                                            <input type="number" id="empSalary" step="0.01" min="0" required>
                                        </div>
                                        <div class="form-group">
                                            <label for="empTarget">绩效目标 <span class="required">*</span></label>
                                            <input type="number" id="empTarget" step="0.01" min="0" required>
                                        </div>
                                    </div>
                                    <div style="margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border-color);">
                                        <h4 style="font-size: 14px; margin-bottom: 15px; color: var(--text-primary);">担保人信息</h4>
                                        <div class="form-group">
                                            <label for="empGuarantorName">担保人姓名</label>
                                            <input type="text" id="empGuarantorName">
                                        </div>
                                        <div class="form-row">
                                            <div class="form-group">
                                                <label for="empGuarantorContact">担保人联系方式</label>
                                                <input type="text" id="empGuarantorContact">
                                            </div>
                                            <div class="form-group">
                                                <label for="empGuarantorRelation">担保人关系</label>
                                                <input type="text" id="empGuarantorRelation" placeholder="如：朋友、亲属等">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-actions">
                                        <button type="submit" class="btn btn-primary">提交</button>
                                        <button type="reset" class="btn btn-secondary">重置</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <div class="panel-card">
                            <div class="card-header">
                                <h3>更新员工信息</h3>
                            </div>
                            <div class="card-body">
                                <form id="updateEmployeeForm" class="form-panel">
                                    <div class="form-group">
                                        <label for="updateEmpId">员工ID <span class="required">*</span></label>
                                        <input type="text" id="updateEmpId" required>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group">
                                            <label for="updateEmpRole">职位</label>
                                            <input type="text" id="updateEmpRole">
                                        </div>
                                        <div class="form-group">
                                            <label for="updateEmpContact">联系方式</label>
                                            <input type="text" id="updateEmpContact">
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group">
                                            <label for="updateEmpSalary">基本工资 (¥)</label>
                                            <input type="number" id="updateEmpSalary" step="0.01" min="0">
                                        </div>
                                        <div class="form-group">
                                            <label for="updateEmpTarget">绩效目标</label>
                                            <input type="number" id="updateEmpTarget" step="0.01" min="0">
                                        </div>
                                    </div>
                                    <div style="margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--border-color);">
                                        <h4 style="font-size: 14px; margin-bottom: 15px; color: var(--text-primary);">担保人信息</h4>
                                        <div class="form-group">
                                            <label for="updateGuarantorName">担保人姓名</label>
                                            <input type="text" id="updateGuarantorName">
                                        </div>
                                        <div class="form-row">
                                            <div class="form-group">
                                                <label for="updateGuarantorContact">担保人联系方式</label>
                                                <input type="text" id="updateGuarantorContact">
                                            </div>
                                            <div class="form-group">
                                                <label for="updateGuarantorRelation">担保人关系</label>
                                                <input type="text" id="updateGuarantorRelation" placeholder="如：朋友、亲属等">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-actions">
                                        <button type="submit" class="btn btn-primary">更新</button>
                                        <button type="reset" class="btn btn-secondary">重置</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <div class="panel-card">
                            <div class="card-header">
                                <h3>更新员工绩效</h3>
                            </div>
                            <div class="card-body">
                                <form id="updatePerformanceForm" class="form-panel">
                                    <div class="form-group">
                                        <label for="perfEmpId">员工ID <span class="required">*</span></label>
                                        <input type="text" id="perfEmpId" required>
                                    </div>
                                    <div class="form-group">
                                        <label for="perfDelta">绩效增量 <span class="required">*</span></label>
                                        <input type="number" id="perfDelta" step="0.01" required>
                                    </div>
                                    <div class="form-actions">
                                        <button type="submit" class="btn btn-primary">更新</button>
                                        <button type="reset" class="btn btn-secondary">重置</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="panel-card">
                        <div class="card-header">
                            <h3>员工列表</h3>
                        </div>
                        <div class="card-body">
                            <div class="table-container">
                                <table class="data-table">
                                    <thead>
                                        <tr>
                                            <th>员工ID</th>
                                            <th>姓名</th>
                                            <th>职位</th>
                                            <th>联系方式</th>
                                            <th>基本工资</th>
                                            <th>绩效目标</th>
                                            <th>当前绩效</th>
                                            <th>实际薪资</th>
                                            <th>担保人</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="employeeList">
                                        <tr><td colspan="10" class="loading">加载中...</td></tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 库存管理 -->
                <div class="tab-panel" id="products">
                    <div class="panel-header">
                        <h2>库存管理</h2>
                    </div>
                    <div class="panel-grid">
                        <div class="panel-card">
                            <div class="card-header">
                                <h3>添加新产品</h3>
                            </div>
                            <div class="card-body">
                                <form id="addProductForm" class="form-panel">
                                    <div class="form-group">
                                        <label for="prodSku">SKU编码 <span class="required">*</span></label>
                                        <input type="text" id="prodSku" required>
                                    </div>
                                    <div class="form-group">
                                        <label for="prodName">产品名称 <span class="required">*</span></label>
                                        <input type="text" id="prodName" required>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group">
                                            <label for="prodCategory">产品类别 <span class="required">*</span></label>
                                            <input type="text" id="prodCategory" required>
                                        </div>
                                        <div class="form-group">
                                            <label for="prodExpiry">过期日期 <span class="required">*</span></label>
                                            <input type="date" id="prodExpiry" required>
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group">
                                            <label for="prodQuantity">库存数量 <span class="required">*</span></label>
                                            <input type="number" id="prodQuantity" min="0" required>
                                        </div>
                                        <div class="form-group">
                                            <label for="prodThreshold">补货阈值 <span class="required">*</span></label>
                                            <input type="number" id="prodThreshold" min="0" required>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="prodPrice">产品单价 (¥) <span class="required">*</span></label>
                                        <input type="number" id="prodPrice" step="0.01" min="0" value="200" required>
                                    </div>
                                    <div class="form-actions">
                                        <button type="submit" class="btn btn-primary">提交</button>
                                        <button type="reset" class="btn btn-secondary">重置</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                        <div class="panel-card">
                            <div class="card-header">
                                <h3>产品补货</h3>
                            </div>
                            <div class="card-body">
                                <form id="restockForm" class="form-panel">
                                    <div class="form-group">
                                        <label for="restockSku">SKU编码 <span class="required">*</span></label>
                                        <input type="text" id="restockSku" required>
                                    </div>
                                    <div class="form-group">
                                        <label for="restockQuantity">补货数量 <span class="required">*</span></label>
                                        <input type="number" id="restockQuantity" min="1" required>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group">
                                            <label for="restockExpiry">更新过期日期（可选）</label>
                                            <input type="date" id="restockExpiry">
                                            <small style="display: block; margin-top: 4px; color: var(--text-secondary); font-size: 12px;">
                                                留空则不更新
                                            </small>
                                        </div>
                                        <div class="form-group">
                                            <label for="restockPrice">更新单价 (¥)（可选）</label>
                                            <input type="number" id="restockPrice" step="0.01" min="0">
                                            <small style="display: block; margin-top: 4px; color: var(--text-secondary); font-size: 12px;">
                                                留空则不更新
                                            </small>
                                        </div>
                                    </div>
                                    <div class="form-actions">
                                        <button type="submit" class="btn btn-primary">提交补货</button>
                                        <button type="reset" class="btn btn-secondary">重置</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="panel-card">
                        <div class="card-header">
                            <h3>产品库存列表</h3>
                        </div>
                        <div class="card-body">
                            <div class="table-container">
                                <table class="data-table">
                                    <thead>
                                        <tr>
                                            <th>SKU</th>
                                            <th>产品名称</th>
                                            <th>类别</th>
                                            <th>单价</th>
                                            <th>库存数量</th>
                                            <th>补货阈值</th>
                                            <th>过期日期</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="productList">
                                        <tr><td colspan="9" class="loading">加载中...</td></tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 销售记录 -->
                <div class="tab-panel" id="sales">
                    <div class="panel-header">
                        <h2>销售记录</h2>
                    </div>
                    <div class="panel-card">
                        <div class="card-header">
                            <h3>记录新销售</h3>
                        </div>
                        <div class="card-body">
                            <form id="saleForm" class="form-panel">
                                <div class="form-row">
                                    <div class="form-group">
                                        <label for="saleSku">SKU编码 <span class="required">*</span></label>
                                        <input type="text" id="saleSku" required>
                                    </div>
                                    <div class="form-group">
                                        <label for="saleQuantity">销售数量 <span class="required">*</span></label>
                                        <input type="number" id="saleQuantity" min="1" required>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="saleEmployeeId">员工ID (可选)</label>
                                    <input type="text" id="saleEmployeeId" placeholder="留空则不关联员工">
                                </div>
                                <div class="form-actions">
                                    <button type="submit" class="btn btn-primary">提交记录</button>
                                    <button type="reset" class="btn btn-secondary">重置</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

                <!-- 预警中心 -->
                <div class="tab-panel" id="alerts">
                    <div class="panel-header">
                        <h2>预警中心</h2>
                    </div>
                    <div class="panel-grid">
                        <div class="panel-card alert-panel">
                            <div class="card-header">
                                <h3>即将过期的产品</h3>
                                <span class="badge warning-badge" id="expiringBadge">0</span>
                            </div>
                            <div class="card-body">
                                <div class="table-container">
                                    <table class="data-table">
                                        <thead>
                                            <tr>
                                                <th>SKU</th>
                                                <th>产品名称</th>
                                                <th>过期日期</th>
                                            </tr>
                                        </thead>
                                        <tbody id="expiringList">
                                            <tr><td colspan="3" class="loading">加载中...</td></tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="panel-card alert-panel">
                            <div class="card-header">
                                <h3>低库存产品</h3>
                                <span class="badge danger-badge" id="lowStockBadge">0</span>
                            </div>
                            <div class="card-body">
                                <div class="table-container">
                                    <table class="data-table">
                                        <thead>
                                            <tr>
                                                <th>SKU</th>
                                                <th>产品名称</th>
                                                <th>当前库存</th>
                                                <th>补货阈值</th>
                                            </tr>
                                        </thead>
                                        <tbody id="lowStockList">
                                            <tr><td colspan="4" class="loading">加载中...</td></tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 数据分析 -->
                <div class="tab-panel" id="analysis">
                    <div class="panel-header">
                        <h2>数据分析</h2>
                        <div style="display: flex; gap: 12px;">
                            <button class="btn btn-secondary" onclick="exportSalesAnalysis()">导出销量分析</button>
                            <button class="btn btn-secondary" onclick="exportEmployeeQuality()">导出质量分析</button>
                        </div>
                    </div>
                    <div class="panel-grid">
                        <div class="panel-card">
                            <div class="card-header">
                                <h3>产品销量分析</h3>
                            </div>
                            <div class="card-body">
                                <div id="salesAnalysisContent">
                                    <div class="loading">加载中...</div>
                                </div>
                            </div>
                        </div>
                        <div class="panel-card">
                            <div class="card-header">
                                <h3>员工工作质量分析</h3>
                            </div>
                            <div class="card-body">
                                <div class="table-container">
                                    <table class="data-table">
                                        <thead>
                                            <tr>
                                                <th>员工ID</th>
                                                <th>姓名</th>
                                                <th>职位</th>
                                                <th>销售次数</th>
                                                <th>总销售额</th>
                                                <th>完成率</th>
                                                <th>质量评级</th>
                                                <th>实际薪资</th>
                                            </tr>
                                        </thead>
                                        <tbody id="qualityAnalysisList">
                                            <tr><td colspan="8" class="loading">加载中...</td></tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 销售历史 -->
                <div class="tab-panel" id="history">
                    <div class="panel-header">
                        <h2>销售历史记录</h2>
                        <div class="search-box">
                            <input type="text" id="historySearch" placeholder="搜索SKU、产品名称或员工ID..." 
                                   onkeyup="filterSalesHistory()" style="padding: 8px 12px; border: 1px solid var(--border-color); border-radius: 6px; width: 300px;">
                        </div>
                    </div>
                    <div class="panel-card">
                        <div class="card-body">
                            <div class="table-container">
                                <table class="data-table">
                                    <thead>
                                        <tr>
                                            <th>销售ID</th>
                                            <th>SKU</th>
                                            <th>产品名称</th>
                                            <th>数量</th>
                                            <th>销售额</th>
                                            <th>员工ID</th>
                                            <th>销售日期</th>
                                        </tr>
                                    </thead>
                                    <tbody id="salesHistoryList">
                                        <tr><td colspan="7" class="loading">加载中...</td></tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <!-- 消息提示 -->
    <div id="message" class="toast-message"></div>

    <!-- 加载遮罩 -->
    <div id="loadingOverlay" class="loading-overlay">
        <div class="spinner"></div>
    </div>

    <script src="app.js"></script>
</body>
</html>
